{% extends "base.html" %}
  {% block content %}
    {% from "forms/macros.html" import render_field_busqueda %}
    <SCRIPT LANGUAGE="JavaScript">
	
		url = "/rol/modificar/ID/"
		url2 = "/rol/eliminar/ID/"
		url3 = "/rol/consultar/ID/"
		
		id_href = 'mod'
		id_href2 = 'eli'
		id_href3 = 'con'
 
		function obtener_id(id) {
        	link = document.getElementById(id_href)
        	link2 = document.getElementById(id_href2)
        	link3 = document.getElementById(id_href3)
        	new_url = url.replace('ID', id)
        	new_url2 = url2.replace('ID', id)
        	new_url3 = url3.replace('ID', id)
        	link.href = new_url
        	link2.href = new_url2
        	link3.href = new_url3
        
		}
		
		function pregunta(){
    		if(confirm('Esta seguro de que desea eliminar el rol?')){
    			return true;
    		}else{
    			return false;
    		}
    	}
    	
	</SCRIPT>
	<h2><center> Administración de Roles </center> </h2>
    <form method="POST" action={{url_for('roles.administracion_rol')}} class="form"><center>
         {{ form.csrf_token }}  
    
         <table>
         <tr>
              <th></th>
              <th><label>Filtro</label> </th>
              <th>{{ render_field_busqueda(form.nombre, class="input text") }}</th>
        </tr>                         
              <tr>
                  <th></th>
                  <th> <center>ID </center></th>
                  <th> <center> NOMBRE </center></td>
        </tr >                 
                {% for rol in roles %}                 
                      <tr >
                          <th><input type = "radio" name = "seleccionado" id="select" onchange="obtener_id({{rol.id}})"></th>
                          <td> <center>{{ rol.id }} </center></td>
                          <td> <center>{{ rol.nombre }} <center></td>
                       </tr>                  
                {% endfor %}
               
        </table>
       
        <div class="buttons">
                <button type="submit" class="button green">
                Buscar
                </button>
        <button type="submit" class="button green">
                <a href="{{ url_for('roles.crear_rol') }}">Crear</a>
        </button>
        <button type="submit" class="button green">
                <a href="" id="mod">Modificar</a>
        </button>
        <button type="submit" class="button green">
                <a href="" id="con">Consultar</a>
        </button>
        <button type="submit" class="button green" onclick =  "return pregunta()">
                <a href="" id="eli">Eliminar</a>
        </button>
       
        </div>  
                 
   </center> </form>
   
   
  {% endblock %}